# -*- coding:utf-8 -*-
# @Time:2023/5/22 8:59
# @Author: cevent
# @name=tasks定义消费消息任务逻辑
from dj_shop.celery_tasks.sms import constants
# from celery_tasks.sms.communicationCloud.SendTemplateSMS import SendSMS
from communicationCloud.SendTemplateSMS import SendSMS

# 导入main.py中定义的celery实例
# from celery_tasks.main import celeryApp
from dj_shop.celery_tasks.main import celeryApp


# 异步任务：发送短信验证码
# 定义装饰器=函数（装饰异步任务，确保celery识别该任务），传入参数定义'任务别名'，即：name='send_sms_code'
@celeryApp.task(name='send_sms_code')
def sendSmsCode(mobile, shortCode):
    print(f"发送短信任务，电话：{mobile}，验证码：{shortCode}")
    sendReq = SendSMS().send(mobile, [shortCode, constants.IMAGE_CODE_REDIS_EXPIRES // 60],
                             constants.SEND_SMS_TEMPLATE_ID)

    # 返回：成功=0 失败=-1
    return sendReq
